package com.zhdl.hardware.myantenna.service.impl;

import com.project.common.util.ByteHelper;
import com.zhdl.hardware.myantenna.repository.MTPortCmdHandleDao;
import com.zhdl.hardware.ranging.myantenna.service.MTRangingCmdSendService;
import com.zhdl.hardware.robot.borunte.repository.impl.BorunteCmdHandleDaoImpl;
import com.zhdl.hardware.robot.borunte.service.impl.BorunteCmdSendServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigInteger;

@Slf4j
@Service
public class MTRangingCmdSendServiceImpl implements MTRangingCmdSendService {

    @Resource
    private MTPortCmdHandleDao cmdHandleDao;

    @Override
    public void MTRangingRun(String port) {
        cmdHandleDao.mtRangingRun(port, bytes -> {
            String s = ByteHelper.bytesArrayToHexString(bytes);
            BigInteger bigInteger = new BigInteger(s, 16);
            int distance = bigInteger.intValue();
            distance = distance * 1000;
            int pickZ = BorunteCmdHandleDaoImpl.originZ + 75000 - distance;
            BorunteCmdSendServiceImpl.pickZ = pickZ;
            log.info("pickZ -------->" + pickZ);
        });
    }

}
